package handler

import (
	"github.com/gin-gonic/gin"
	"management/api/register"
	"management/initlist/mysql"
	"management/inits/model"
)

func CampusAdd(r *gin.Context) {
	var req register.Campus
	err := r.ShouldBind(&req)
	if err != nil {
		r.JSON(400, &Res{
			Code:    400,
			Message: "参数失败",
			Data:    nil,
		})
		return
	}
	campus := model.Campus{
		City:         req.City,
		CampusId:     req.CampusId,
		CampusName:   req.CampusName,
		ContactPhone: req.ContactPhone,
		ContactEmail: req.ContactEmail,
		Area:         req.Area,
	}
	mysql.DB.Debug().Create(&campus)
	r.JSON(200, &Res{
		Code:    200,
		Message: "完善校区信息添加成功",
		Data:    campus,
	})
}

func CampusList(r *gin.Context) {
	var req register.Campus
	err := r.ShouldBind(&req)
	if err != nil {
		r.JSON(400, &Res{
			Code:    400,
			Message: "参数失败",
			Data:    nil,
		})
		return
	}
	var all []model.Campus
	mysql.DB.Debug().Find(&all)
	r.JSON(200, &Res{
		Code:    200,
		Message: "展示成功",
		Data:    all,
	})
}
